//
//  DDInterViewCell.swift
//  DingDongZP
//
//  Created by 三秒文化 on 2016/10/25.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

import UIKit

class DDInterViewCell: LDBaseCells {
    
    var titleArr = ["dga","dga","et","fdg"]
    var model:DDInterviewListModel? {
        didSet{
//            let str = model?.yy_modelToJSONString()
//            debugPrint(str)
            updateUI()
        }
    }
    
    
    //默认面试类型
    private var interviewType = DDWaitInterviewType.Present
    
    private var headImgV = { return UIImageView(image: UIImage.init(named: "default_header"))}()
    private var nameLab = { return UILabel.setBaseLab("ANNA", fontSize: 14, titleColor: LDFontColor.Black, Alignment: .Center) }()
    private var jobLab = { return UILabel.setBaseLab("设计师", fontSize: 15, titleColor: LDFontColor.Black, Alignment: .Left)}()
    private var interviewTypeLab = { return UILabel.setBaseLab("面试邀请", fontSize: 14, titleColor: LDFontColor.LightGray, Alignment: .Left)}()
    private var interviewStatusLab = { return UILabel.setBaseLab("待面试", fontSize: 11, titleColor: LDFontColor.White, Alignment: .Center)}()
    private var lineImg = { return UIImageView.setupDivideLine_H(LDFrame.ScreenWidth - 110)}()
    
    private var textTypeLab = { return UILabel.setBaseLab("面试邀请1", fontSize: 13, titleColor: LDFontColor.LightGray, Alignment: .Left)}()
    private var textPhoneLab = { return UILabel.setBaseLab("面试邀请2", fontSize: 13, titleColor: LDFontColor.LightGray, Alignment: .Left)}()
    private var textDate = { return UILabel.setBaseLab("面试邀请3", fontSize: 13, titleColor: LDFontColor.LightGray, Alignment: .Left)}()
    private var textLocale = { return UILabel.setBaseLab("面试邀请4", fontSize: 13, titleColor: LDFontColor.LightGray, Alignment: .Left)}()
    
    
    
    private let imgLeft:CGFloat = 20
    private let imgTop:CGFloat = 35
    private let imgH:CGFloat = 60
    private let cellH:CGFloat = 142 + 14
    
    init(interviewType:DDWaitInterviewType?, cellType: LDBaseCellType, margin: CGFloat, style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(type: cellType, margin: margin, style: .Default, reuseIdentifier: reuseIdentifier)
        initSubviews()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //
    func updateUI() {
        
        let urlStr = LDCommentAPI.getPicApi(model?.emplogo)
        headImgV.setImageWithURL(NSURL(string: urlStr)!, placeholderImage: LDDefault.JobFinderLogoImg)
        nameLab.text = model?.name
        jobLab.text = model?.job_title
        
        if model?.type == "1" {
            
            interviewType = DDWaitInterviewType.Present
        } else {
            
            interviewType = DDWaitInterviewType.Video
        }
        
        //显示state
        switch model!.state {
        case LDInterviewStatesType.WaitInterView.rawValue:
            
            interviewStatusLab.text = DDInterviewSendModel.InterviewState.agree
            interviewStatusLab.backgroundColor = LDFontColor.Orange
        case LDInterviewStatesType.CancelInterView.rawValue:
            
            interviewStatusLab.text = DDInterviewSendModel.InterviewState.cancel
            interviewStatusLab.backgroundColor = LDFontColor.DeepGray
        case LDInterviewStatesType.InterViewOver.rawValue:
            
            interviewStatusLab.text = DDInterviewSendModel.InterviewState.finish
            interviewStatusLab.backgroundColor = LDFontColor.DeepGray
        case LDInterviewStatesType.Reject.rawValue:
            
            interviewStatusLab.text = DDInterviewSendModel.InterviewState.reJect
            interviewStatusLab.backgroundColor = LDFontColor.DeepGray
        default:
            
            interviewStatusLab.text = DDInterviewSendModel.InterviewState.none
            interviewStatusLab.backgroundColor = LDFontColor.DeepGray
        }
        
        
        if interviewType == .Present{
        
            textTypeLab.text = String.init(format: "面试类型: %@", "到场面试")
            
        } else {
            
            textTypeLab.text = String.init(format: "面试类型: %@",  "在线面试")
            
        }
        
        textPhoneLab.text = String.init(format: "联系方式: %@", model?.link_mobile ?? "未填写")
        textDate.text = String.init(format: "面试时间: %@", model?.interviewdt ?? "到场面试")
        textLocale.text = String.init(format: "面试地点: %@", model?.address ?? "到场面试")
        
        layoutUI()
    }
    
    //初始化视图
    func initSubviews() {
        
        headImgV.layer.cornerRadius = imgH/2
        headImgV.layer.masksToBounds = true
        
        interviewStatusLab.backgroundColor = LDFontColor.Orange
        interviewStatusLab.layer.cornerRadius = 8
        interviewStatusLab.layer.masksToBounds = true
        
        backgroundColor = LDGolbalColor.BgGoundGray
        
        
        addSubview(headImgV)
        addSubview(nameLab)
        addSubview(jobLab)
        addSubview(interviewTypeLab)
        addSubview(interviewStatusLab)
        addSubview(lineImg)
        addSubview(textTypeLab)
        addSubview(textPhoneLab)
        addSubview(textDate)
        addSubview(textLocale)
    }
   

}


//
extension DDInterViewCell {
    
    //自动布局
    func layoutUI() {
        
        headImgV.snp_remakeConstraints { (make) in
            
            make.left.equalTo(imgLeft)
            make.centerY.equalTo(self).offset(-LDMargin_V*1.5)
            make.size.equalTo(CGSizeMake(imgH, imgH))
        }
        
        nameLab.snp_remakeConstraints { (make) in
            
            make.centerX.equalTo(headImgV)
            make.top.equalTo(headImgV.snp_bottom).offset(LDMargin_V*2)
            make.height.equalTo(20)
        }
        //-----------------------
        var marT:CGFloat = 0
        if interviewType == .Video {
            
            marT = LDMargin_V*6.5
        } else {
            marT = LDMargin_V*5
        }
        
        jobLab.snp_remakeConstraints { (make) in
            
            make.top.equalTo(marT)
            make.left.equalTo(headImgV.snp_right).offset(LDMargin_V*5)
            make.height.equalTo(20)
        }
        
        interviewTypeLab.snp_remakeConstraints { (make) in
            
            make.centerY.equalTo(jobLab)
            make.left.equalTo(jobLab.snp_right).offset(LDMargin_V)
            make.height.equalTo(20)
        }
        
        interviewStatusLab.snp_remakeConstraints { (make) in
            
            make.centerY.equalTo(jobLab)
            make.left.equalTo(interviewTypeLab.snp_right).offset(LDMargin_V*3)
            make.size.equalTo(CGSizeMake(50, 15))
        }
        
        lineImg.snp_remakeConstraints { (make) in
            
            make.left.equalTo(jobLab)
            make.top.equalTo(jobLab.snp_bottom).offset(LDMargin_V)
            make.right.equalTo(0)
            make.height.equalTo(0.6)
        }
        
        //-----------------------面试desc
        
        if interviewType == .Video {
            //面试类型
            textTypeLab.snp_remakeConstraints { (make) in
                
                make.left.equalTo(jobLab)
                make.top.equalTo(lineImg.snp_bottom).offset(LDMargin_V*1.5)
                make.height.equalTo(18)
                make.right.equalTo(0)
            }
            //面试时间
            textDate.snp_remakeConstraints { (make) in
                
                make.left.height.right.equalTo(textTypeLab)
                make.top.equalTo(textTypeLab.snp_bottom).offset(LDMargin_V)
            }
            
            textPhoneLab.hidden = true
            textLocale.hidden = true
            
            
        } else {
            
            textPhoneLab.hidden = false
            textLocale.hidden = false
            
            textTypeLab.snp_remakeConstraints { (make) in
                
                make.left.equalTo(jobLab)
                make.top.equalTo(lineImg.snp_bottom).offset(LDMargin_V*1.5)
                make.height.equalTo(15)
                make.right.equalTo(0)
            }
            
            textPhoneLab.snp_remakeConstraints { (make) in
                
                make.left.height.right.equalTo(textTypeLab)
                make.top.equalTo(textTypeLab.snp_bottom).offset(LDMargin_V)
            }
            
            textDate.snp_remakeConstraints { (make) in
                
                make.left.height.right.equalTo(textTypeLab)
                make.top.equalTo(textPhoneLab.snp_bottom).offset(LDMargin_V)
            }
            
            textLocale.snp_remakeConstraints { (make) in
                
                make.left.height.right.equalTo(textTypeLab)
                make.top.equalTo(textDate.snp_bottom).offset(LDMargin_V)
            }
        }
    
        
    }
}
